package guda.house.biz.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import guda.house.biz.EstateBiz;
import guda.house.dal.dao.EstateDAO;
import guda.house.dal.dataobject.EstateDO;
import guda.grape.autogen.common.page.BaseQuery;
import guda.grape.autogen.common.page.BizResult;

public class EstateBizImpl implements EstateBiz{

    private final static Logger logger = LoggerFactory.getLogger(EstateBizImpl.class);

    @Autowired
    private EstateDAO estateDAO;

    public BizResult detail(long id) {
        BizResult bizResult = new BizResult();
        try{
            EstateDO estateDO = estateDAO.getEstateById(id);
            bizResult.data.put("estateDO", estateDO);
            bizResult.success = true;
        }catch(Exception e){
            logger.error("query Estate error",e);
        }
        return bizResult;
}

    public BizResult list(BaseQuery baseQuery) {
        BizResult bizResult = new BizResult();
        try {
            int totalCount = estateDAO.countForPage(baseQuery);
            baseQuery.setTotalCount(totalCount);
            List<EstateDO> estateList = estateDAO.selectForPage(baseQuery);
            bizResult.data.put("estateList", estateList);
            bizResult.data.put("query", baseQuery);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("view Estate list error", e);
        }
            return bizResult;
     }

    public BizResult delete(long id) {
        BizResult bizResult = new BizResult();
        try {
            estateDAO.delEstateById(id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("delete estate error", e);
        }
        return bizResult;
    }

    public BizResult create(EstateDO estateDO) {
        BizResult bizResult = new BizResult();
        try {
            long id = estateDAO.insert(estateDO);
            bizResult.data.put("id", id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("create Estate error", e);
        }
        return bizResult;
    }

    @Override
    public BizResult update(EstateDO estateDO) {
        BizResult bizResult = new BizResult();
        try {
            estateDAO.updateByIdSelective(estateDO);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("update Estate error", e);
        }
        return bizResult;
    }



}
